package pl.lodz.p.mbus;

import com.serotonin.modbus4j.ModbusFactory;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.ip.IpParameters;

import android.app.Application;

public class MbusApplication extends Application {

	private ModbusMaster master;

	@Override
	public void onCreate() {
		super.onCreate();
		modbusInit();
	}

	public void modbusInit() {
		ModbusFactory factory = new ModbusFactory();
		IpParameters params1 = new IpParameters();
		params1.setHost("10.7.12.60");
		params1.setPort(502);
		params1.setEncapsulated(false);
		setMaster(factory.createTcpMaster(params1, false));
		getMaster().setTimeout(2000);
		getMaster().setRetries(2);

		try {
			getMaster().init();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			getMaster().destroy();
		}

	}

	public ModbusMaster getMaster() {
		return master;
	}

	public void setMaster(ModbusMaster master) {
		this.master = master;
	}

}
